/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gitee.huangjianbo.supos.openapi.core.errors;

/**
 * 无效的响应异常
 * 
 * @author tomcat
 * @version 1.0
 */
public class InvalidResponseException extends ApiClientException {

    private static final long serialVersionUID = -6580153906899111391L;

    /**
     * 状态码
     */
    private final int statusCode;
    /**
     * 错误响应
     */
    private ErrorResponse errorResponse;

    /**
     * 构造函数
     * 
     * @param statusCode HTTP状态码
     * @param message    错误信息
     */
    public InvalidResponseException(int statusCode, String message) {
        super("status=" + statusCode + ", message=" + message);
        this.statusCode = statusCode;
    }

    /**
     * 构造函数
     * 
     * @param statusCode HTTP状态码
     * @param message    错误信息
     * @param throwable  异常
     */
    public InvalidResponseException(int statusCode, String message, Throwable throwable) {
        super("status=" + statusCode + ", message=" + message + ", exception=" + throwable.getMessage(), throwable);
        this.statusCode = statusCode;
    }

    /**
     * 构造函数
     * 
     * @param statusCode    HTTP状态码
     * @param errorResponse 错误响应
     */
    public InvalidResponseException(int statusCode, ErrorResponse errorResponse) {
        super("status=" + statusCode + ", message=" + errorResponse.getMessage() + ", code=" + errorResponse.getCode()
                + ", target=" + errorResponse.getTargetService());
        this.statusCode = statusCode;
        this.errorResponse = errorResponse;
    }

    /**
     * 构造函数
     * 
     * @param statusCode    HTTP状态码
     * @param errorResponse 错误响应
     * @param throwable     异常
     */
    public InvalidResponseException(int statusCode, ErrorResponse errorResponse, Throwable throwable) {
        super("status=" + statusCode + ", message=" + errorResponse.getMessage() + ", code=" + errorResponse.getCode()
                + ", target=" + errorResponse.getTargetService() + ", exception=" + throwable.getMessage(), throwable);
        this.statusCode = statusCode;
        this.errorResponse = errorResponse;
    }

    public ErrorResponse getErrorResponse() {
        return errorResponse;
    }

    public int getStatusCode() {
        return statusCode;
    }
}
